/**声音文件类：包含了在WingSound已经载入的声音文件
 * date 2011 5 10
 * author @zzy
 */
package cn.edu.dlut.WingGame.Sound;

//import android.util.Log;

public class SoundFile {

	private int id;
	private int result;
	private SoundStream soundStream;

	// private boolean res;

	public SoundFile(int streamID) {
		id = streamID;
	}

	public int getID() {
		return id;
	}

	public SoundStream play() { // 返回正在播放音乐的声音流
		if (WingSound.mute == true)
			return null;

		/*
		 * 播放音频函数，可以对左右音量分别设置，还可以设置优先级，循环次数以及速率 优先级的值越大优先级越高
		 * 循环次数0为只播放一次，-1代表无限循环，其他值为播放loop+1次 速率最低为0.5，最高为2，1代表正常速度
		 */
		result = WingSound.soundPlay.getSoundPool().play(id,
				WingSound.soundPlay.getVolume(),
				WingSound.soundPlay.getVolume(), 1, 0, 1);

		if (result != 0) {
			soundStream = new SoundStream(result, false, WingSound.soundPlay
					.getVolume());
			return soundStream;
		} else
			return null;
	}

	public SoundStream playContinuous() { // 返回持续播放音乐的声音流
		if (WingSound.mute == true)
			return null;

		result = WingSound.soundPlay.getSoundPool().play(id,
				WingSound.soundPlay.getVolume(),
				WingSound.soundPlay.getVolume(), 0, -1, 1);

		if (result != 0) {
			soundStream = new SoundStream(result, false, WingSound.soundPlay
					.getVolume());
			return soundStream;
		} else
			return null;
	}

	public void unload() {
		WingSound.soundPlay.getSoundPool().unload(id);
		// res = WingSound.musicPlay.getSoundPool().unload(id);
		// Log.v("Unloading ", " ");
	}
}
